import { defineStore } from 'pinia'
import { categoryImg, categoryList } from '@/views/category/category'

export const setCategoryList = defineStore('category', {
  state() {
    return {
      categoryL1List: [] as any,

      categoryL2List: [] as any,
      categoryGroupList: [] as any,
      currentCategory: {} as any,
      currentId: 11
    }
  },

  actions: {
    async getCategoryAsync() {
      const res = await categoryList()

      this.categoryL1List = res.data.categoryL1List
      // this.currentCategory = res.data.currentCategory
    },
    async getCatgoryList(id: number) {
      const res = await categoryImg(this.currentId)
      this.categoryL2List = res.data.categoryGroupList

      this.currentCategory = res.data.currentCategory
    }
  },
  getters: {
    // 大图
    bannerImg(state) {
      return ((state.currentCategory.bannerList || [])[0] || {}).picUrl || ''
    }
  }
})
